/**
* @author Cheng Liu
**/

#pragma once

#include "CinePlugin.h"
#include "TagFileBuffer.h"
#include <windows.h>
#include <string>
#include <vector>

class CtagsCompleter : public IPlugin
{
public:
	CtagsCompleter();
	~CtagsCompleter();

	void Initialize(IPluginFacade* Cine);
	void Release();

	void Activate();
	void Deactivate();
	bool HandleEvent(Events::Event * event);
	
	void LoadCommonFromPath(const char * path);

	bool initOver;
private:
	IPluginFacade *cine;
	bool ExecuteShellCommand(LPTSTR commandLine, LPCTSTR workPath, unsigned int timeOut=3000);
	std::string GetTagsFile(const char* path);
	void GetNearestTags(const char* tagfile, const char* prefix, std::vector<std::string> *wordList);
	std::string GetTagType(const char* tagfile, const char * tag);
	std::string tryGetType(const char*);
	void GetFieldTags(const char* tagfile, std::string field, std::vector<std::string> *wordList);
	std::string BuildTempTags(const char* file);

private:
	std::string common_tag;
	TagFileBuffer * tfb;
	DWORD tid;
	HANDLE hThread;
	std::basic_string<TCHAR> dpath;
	TCHAR buf_cmd[1000];
};

